package org.initialize4j.convert;

import java.lang.reflect.Field;

/**
 * Factory creating specific {@link Converter}s.
 * 
 * @author <a href="hillger.t@gmail.com">hillger.t</a>
 */
//TODO Has to be necessarily refactored! Code smells - to much if/else
public final class FieldConverterFactory {

  /**
   * Creates a {@link Converter} for a provided {@link Field} instance.
   * 
   * @param field The {@link Field} to inspect.
   * @return {@link Converter}
   */
  public Converter<?> getConverter(Field field) {
    if (field.getType().equals(Integer.class)) {
      return new IntegerConverter();
    }
    else if (field.getType().equals(Long.class)) {
      return new LongConverter();
    }
    else if (field.getType().equals(Boolean.class)) {
      return new BooleanConverter();
    }
    else if (field.getType().equals(Float.class)) {
      return new FloatConverter();
    }
    else if (field.getType().equals(Double.class)) {
      return new DoubleConverter();
    }
    else if (field.getType().equals(String.class)) {
      return new StringConverter();
    }

    return new NullConverter();
  }
}
